//
//  QGLoginPageViewController.m
//  QuanGou
//
//  Created by lanou3g on 15/11/17.
//  Copyright © 2015年 LiuFei. All rights reserved.
//

#import "QGLoginPageViewController.h"
#import "QGRegistRootViewController.h"
#import "QGLoginPageViewController.h"
#import "QGUITabBarController.h"

#import <AVUser.h>

@interface QGLoginPageViewController ()
@property (weak, nonatomic) IBOutlet UITextField *telePhoneTextField;
@property (weak, nonatomic) IBOutlet UITextField *passwordTextField;

@end

@implementation QGLoginPageViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    self.telePhoneTextField.clearButtonMode = YES;
    self.passwordTextField.clearButtonMode = YES;
    
}





#pragma mark ==== button方法
- (IBAction)registButtonAction:(UIButton *)sender {

    QGRegistRootViewController *registVC = [[QGRegistRootViewController alloc] initWithNibName:@"QGRegistRootViewController" bundle:nil];
    

    [self.navigationController pushViewController:registVC animated:YES];
}
- (IBAction)loginButtonAction:(UIButton *)sender {
//    
//    [AVUser logInWithMobilePhoneNumberInBackground:@"18612340000" password:@"yourpassword" block:^(AVUser *user, NSError *error) {
//        if (user != nil) {
//            NSLog(@"登陆成功");
//        }else{
//            UIAlertController *alertControlelr = [UIAlertController alertControllerWithTitle:@"提示" message:nil preferredStyle:(UIAlertControllerStyleAlert)];
//            UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"账号或密码错误" style:(UIAlertActionStyleCancel) handler:nil];
//            [alertControlelr addAction:cancelAction];
//            [self presentViewController:alertControlelr animated:YES completion:nil];
//        }
//        
//    }];
    
    
    
    [AVUser logInWithUsernameInBackground:self.telePhoneTextField.text  password:self.passwordTextField.text block:^(AVUser *user, NSError *error) {
        if (user != nil || !error) {
            NSLog(@"登陆成功");
            QGUITabBarController *qgVC = [[QGUITabBarController alloc]init];

            [self presentViewController:qgVC animated:YES completion:nil];
            
        } else {
            UIAlertController *alertControlelr = [UIAlertController alertControllerWithTitle:@"提示" message:nil preferredStyle:(UIAlertControllerStyleAlert)];
            UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"账号或密码错误" style:(UIAlertActionStyleCancel) handler:nil];
            [alertControlelr addAction:cancelAction];
            [self presentViewController:alertControlelr animated:YES completion:nil];
        }
    }];
}
- (IBAction)thirdWayLoginAction:(UIButton *)sender {
  
    
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
